package org.example.completed.controller;

import org.example.completed.domain.Comment;
import org.example.completed.model.dto.CommentAndAvatarDTO;
import org.example.completed.model.vo.ResultVO;
import org.example.completed.service.CommentService;
import org.example.completed.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comments")
public class CommentController {

    private final CommentService commentService;

    @Autowired
    public CommentController(CommentService commentService) {
        this.commentService = commentService;
    }

    // 获取所有评论，包括用户名和头像
    @GetMapping
    public List<Comment> getAllComments() {
        return commentService.getAllComments();
    }

    // 添加评论
    @PostMapping
    public void addComment(@RequestBody Comment comment) {
        commentService.addComment(comment);
    }

    @GetMapping("/getCommentsByUsernameWithAvatar")
    public ResultVO<CommentAndAvatarDTO> getCommentsByUsernameWithAvatar(@RequestParam String username) {
        CommentAndAvatarDTO commentAndAvatarDTO = commentService.getCommentsByUsernameWithAvatar(username);
        return ResultVO.ok(commentAndAvatarDTO);
    }
}